package com.tbit.main.constant;


import org.apache.commons.lang3.StringUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 故障类型
 *
 * @Author LHX
 * @ClassName FaultType
 * @Description
 * @date 2023/5/19 11:29
 * @Version 1.0
 */
public class FaultTypeConstant {

    /**
     * 维修记录的故障类型
     */
    static final Map<String, String> REPAIR_ABNORMAL = new HashMap<>();

    /*
     * x-1 表示客户端故障
     * x-3 表示匹配运维端上报故障-维修记录
     */
    static {
        REPAIR_ABNORMAL.put("0", "其他");
        REPAIR_ABNORMAL.put("1", "刹车");
        REPAIR_ABNORMAL.put("2", "转把手");
        REPAIR_ABNORMAL.put("3", "车撑");
        REPAIR_ABNORMAL.put("4", "二维码");
        REPAIR_ABNORMAL.put("5", "中控");
        REPAIR_ABNORMAL.put("6", "喇叭故障");
        REPAIR_ABNORMAL.put("7", "电池");
        REPAIR_ABNORMAL.put("8", "电池锁");
        REPAIR_ABNORMAL.put("9", "头盔锁");
        REPAIR_ABNORMAL.put("0-3", "转把手");
        REPAIR_ABNORMAL.put("1-3", "车灯");
        REPAIR_ABNORMAL.put("2-3", "线路");
        REPAIR_ABNORMAL.put("3-3", "车篮");
        REPAIR_ABNORMAL.put("4-3", "车轮");
        REPAIR_ABNORMAL.put("5-3", "车撑");
        REPAIR_ABNORMAL.put("6-3", "刹车");
        REPAIR_ABNORMAL.put("7-3", "车座");
        REPAIR_ABNORMAL.put("8-3", "二维码");
        REPAIR_ABNORMAL.put("9-3", "电池");
        REPAIR_ABNORMAL.put("10-3", "脚蹬");
        REPAIR_ABNORMAL.put("11-3", "前叉");
        REPAIR_ABNORMAL.put("12-3", "挡泥板");
        REPAIR_ABNORMAL.put("13-3", "控制器");
        REPAIR_ABNORMAL.put("14-3", "中控");
        REPAIR_ABNORMAL.put("15-3", "响铃铛");
        REPAIR_ABNORMAL.put("16-3", "电池锁");
        REPAIR_ABNORMAL.put("50-3", "其他");
    }

    /**
     * 匹配运维上传维修记录异常记录类型
     */
    public static String matchFaultType(String faults, Integer faultType) {
        if (StringUtils.isBlank(faults)) {
            return "";
        }
        List<String> faultsList = Arrays.stream(faults.split(","))
                .map(x -> {
                    if (Objects.equals(3, faultType)) {
                        return REPAIR_ABNORMAL.get(x + "-3");
                    }
                    return StringUtils.defaultIfBlank(REPAIR_ABNORMAL.get(x), x);
                })
                .collect(Collectors.toList());
        return StringUtils.join(faultsList, ",");
    }

    public static String parse(int fault, int faultType) {
        if (faultType == 3) {
            return REPAIR_ABNORMAL.get(fault + "-3");
        }
        return REPAIR_ABNORMAL.get(String.valueOf(fault));
    }

}
